
//这种用户token 与用户信息的设计...有点东西
const tokens = {
  //设置用户们的token
  admin: {
    token: 'admin-token'
  },
  editor: {
    token: 'editor-token'
  },
  //添加用户2
  editor2: {
    token: 'editor2-token'
  }
}
//用户列表
const users = {
  //根据token名字设置其对应信息
  'admin-token': {
    roles: ['admin'],
    introduction: 'I am a super administrator',
    avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    name: 'Super Admin',
    age:20,
    hobby:'chifan'
  },
  'editor-token': {
    roles: ['editor'],
    introduction: 'I am an editor',
    avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    name: 'Normal Editor',
    age:21,
    hobby:'sleep'
  },
  'editor2-token': {
    roles: ['editor2'],
    introduction: 'I am an editor2',
    avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    name: 'Normal Editor2',
    age:22,
    hobby:'run'
  }
}


/*console.log(tokens.admin.token,tokens.editor.token,tokens.editor2.token)
console.log(users["admin-token"])
console.log(users[tokens.admin.token])*/
module.exports = [
  //mock用户登录
  {
    url: '/vue-admin-template/user/login',
    type: 'post',
    response: config => {
      console.log("config:")
      console.log(config.body)
      const { username } = config.body
      //通过用户名字 赋值对应token值()
      const token = tokens[username]
      // mock error
      if (!token) {
        return {
          code: 60204,
          message: 'Account and password are incorrect.账户或密码不正确'
        }
      }
      return {
        code: 20000,
        data: token
      }
    }
  },

  // 获取mock用户信息  \.*谁的信息 （后面无论出现什么都会被拦截）占位作用
  {
    url: '/vue-admin-template/user/info\.*',
    type: 'get',
    response: config => {
      console.log("configInfo:")
      console.log(config.query)
      //请求参数信息
      const { token } = config.query
      //根据user的token获取信息users[token] 为用户信息
      const info = users[token]
      console.log('--------')
      console.log(info)
      // mock error
      if (!info) {
        return {
          code: 50008,
          message: 'Login failed, unable to get user details.登录失败不能获取用户详情'
        }
      }
      //这个是反给axios的
      return {
        code: 20000,
        data: info,
        myData:123456789
      }
    }
  },

  // 用户mock退出登录
  {
    url: '/vue-admin-template/user/logout',
    type: 'post',
    response: _ => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  }
]
